package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.Tools;
import com.example.rbacmanage.service.app.ToolsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/background/tools")
@RestController
public class ToolsController {
    @Autowired
    private ToolsService toolsService;

    @PreAuthorize("hasAnyAuthority('background:tools:page')")
    @GetMapping("/page")
    public Result page(Tools tools){
        return Result.success(toolsService.getPage(tools));
    }
    @GetMapping("/{id}")
    public Result info(@PathVariable("id")Long id){
        return Result.success(toolsService.getById(id));
    }
    @PreAuthorize("hasAnyAuthority('background:tools:add')")
    @PostMapping("/add")
    public Result add(@RequestBody Tools tools){
        toolsService.save(tools);
        return Result.success();
    }
    @PreAuthorize("hasAnyAuthority('background:tools:update')")
    @PutMapping("/update")
    public Result update(@RequestBody Tools tools){
        toolsService.update(tools);
        return Result.success();
    }
    @PreAuthorize("hasAnyAuthority('background:tools:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        toolsService.remove(ids);
        return Result.success();
    }
}
